package bookstore.interceptor;

import bookstore.model.Customer;
import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.*;

/**
 * Description:
 * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@163.com
 * @version  1.0
 */
// 权限检查拦截器继承AbstractInterceptor类
public class AuthorityInterceptor
	extends AbstractInterceptor
{
	// 拦截Action处理的拦截方法
	public String intercept(ActionInvocation invocation)
		throws Exception
	{
		// 取得请求相关的ActionContext实例
		ActionContext ctx = invocation.getInvocationContext();
		Map session = ctx.getSession();
		// 取出Session里的user属性
		 Customer username = ( Customer)session.get("bsCustomer");
		//如果没有登录，或者登录所用的用户名不是crazyit.org，都返回重新登录
		if (username != null )
		{
			return invocation.invoke();
		}
                session.put("tip","1");
		// 如果没有登录，将服务器提示放入ActionContext中
		ctx.put("tip" ,"您还没有登录，请输入crazyit.org,leegang登录系统");
		// 返回login的逻辑视图
		return Action.LOGIN;
	}
}
